﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace EmailManager
{
    public static class Config
    {
        public static string Email;
        public static string AuthCode;
        public static string ContentBefore;
        public static string ContentAfter;
        public static string SenderName;
        public static string Topic;
        public static void Init()
        {
            var path = Path.Join(Environment.CurrentDirectory, "emailconfig.txt");
            using var sr = new StreamReader(path);
            var config = sr.ReadToEnd();
            var list = config.Split("&;\r\n");
            var dictionary = new Dictionary<string, string>();
            foreach (var item in list)
            {
                var kv = item.Split("=");
                var key = kv[0];
                var value = kv[1];
                dictionary.Add(key, value);
            }
            if (dictionary.ContainsKey("Email"))
            {
                Email = dictionary["Email"];
            }
            if (dictionary.ContainsKey("AuthCode"))
            {
                AuthCode = dictionary["AuthCode"];
            }
            if (dictionary.ContainsKey("ContentBefore"))
            {
                ContentBefore = dictionary["ContentBefore"];
            }
            if (dictionary.ContainsKey("ContentAfter"))
            {
                ContentAfter = dictionary["ContentAfter"];
            }
            if (dictionary.ContainsKey("SenderName"))
            {
                SenderName = dictionary["SenderName"];
            }
            if (dictionary.ContainsKey("Topic"))
            {
                Topic = dictionary["Topic"];
            }
        }
    }
}
